<?php

namespace app\admin\controller;

use think\Request;

use app\admin\model\WithdrawModel;

class Withdraw extends Base
{
    //用户列表
    public function index()
    {
        if(request()->isAjax()){

            $param = input('param.');

            $limit = $param['pageSize'];
            $offset = ($param['pageNumber'] - 1) * $limit;

            $where = [];
            if (!empty($param['searchText'])) {
                $where[] = ['billcode', 'like', '%' . $param['searchText'] . '%'];
            }
            $user = new WithdrawModel();
            $selectResult = $user->getUsersByWhere($where, $offset, $limit);

            // 拼装参数
            foreach($selectResult as $key=>$vo){

                // $selectResult[$key]['sendphone'] = $vo->sender;
                // $selectResult[$key]['uphone'] = $vo->memberModel()->value('memb_phone');

                $selectResult[$key]['operate'] = showOperate($this->makeButton($vo['id']));
            }
            $return['total'] = $user->getAllUsers($where);  //总数据
            $return['rows'] = $selectResult;
            return json($return);
        }

        return $this->fetch();
    }

    public function updataStatus(){
        $id = input('id');
        $wd = new WithdrawModel();
        return $wd->updateStatus($id);
    }

    /**
     * 拼装操作按钮
     * @param $id
     * @return array
     */
     private function makeButton($id)
     {
        if(db('withdraw')->where('id', $id)->value('status') == 0){
            return [
                '处理完成' => [
                    'auth' => 'sendorder/edit',
                    'href' => "javascript:updataStatus(" .$id .")",
                    'btnStyle' => 'primary',
                    'icon' => 'fa fa-paste'
               ]
            ];
        }
     }
}
